package com.dzm.controller;

import com.dzm.client.StudentClient;
import com.dzm.service.EmpService;
import com.dzm.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：Dzm
 * 时间：2024-08-21-15:36
 * 功能：
 */

@RestController
@RequestMapping("/emp")
@RefreshScope
public class EmpController {

    @Value("${emp.name}")
    private String name;

    @Autowired
    private EmpService empService;

    @Autowired
    private StudentClient studentClient;

    @GetMapping("/getEmpName")
    public R get() {
        return R.ok().data("name", name);
    }

    @GetMapping("list")
    public R list(@RequestHeader("hello") String header) {  //获取请求头
        System.out.println("header---hello：" + header);
        return R.ok().data("list", empService.list());
    }

    @GetMapping("/studentList")
    public R studentList() {
        return R.ok().data("studentList", studentClient.list());
    }

    @GetMapping("/getStudentById/{id}")
    public R getById(@PathVariable("id")Integer id) {
        return R.ok().data("stu", studentClient.getById(id));
    }

    @GetMapping("/getStudentById2/{id}")
    public R getById2(@PathVariable("id")Integer id) {
        return empService.getStudentById2(id);
    }


}
